<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>


    <script>
        //正则
        // var reg = /[a-z]+/
        // if (reg.test("hello12")) { //判断字符串是否匹配正则
        //     alert("true")
        // } else {
        //     alert("false")
        // }



        var reg1 = /java+/i //(g:全局匹配，i:不区分大小写)

        var str = "aJAVA hello java 123 java";
        //console.log(reg1.exec(str));
        var arr;
        while ((arr = reg1.exec(str)) != null) {
            //console.log(arr[0])
            document.write(arr[0] + "<br>");
        }
    </script>
</body>

</html>